var _n87;
var cc__extends = __extends;
var cc__decorate = __decorate;
var cc__importDefault = __importDefault;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $1$EventManager = require("EventManager");
var s = cc__importDefault($1$EventManager);
var $1$Loader = require("Loader");
var c = cc__importDefault($1$Loader);
var $1$yyComponent = require("yyComponent");
var l = cc__importDefault($1$yyComponent);
var $GameEventType = require("GameEventType");
var $zqcc_OverallSystem = require("zqcc_OverallSystem");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_zhutiListItem = function (t) {
  function _ctor() {
    let instance = (t !== null) && t.apply(this, arguments) || this; // 使用let并定义为更具意义的变量名

    // 初始化属性
    instance.icon = null; // 图标
    instance.vicon = null; // 视觉图标
    instance.lockNode = null; // 锁定节点
    instance.xuanzhong = null; // 选中的状态
    instance.data = null; // 数据
    instance.type = 1; // 类型
    instance.ziyuanlujing = null; // 资源路径
    instance.lockData = null; // 锁定数据
    instance.jieduanName = ["小白", "新手", "入门", "熟练", "精英", "高手", "专业", "大师", "宗师", "雀圣", "雀神"]; // 阶段名称

    return instance; // 返回最终的对象
  }
  cc__extends(_ctor, t);
  _ctor.prototype.start = function () {
    this.on($GameEventType.EventType.DirectorEvent.pifugenghuan, this.updataView, this);
  };
  _ctor.prototype.setDatas = function (t, e) {
    let storageInfo = t["储存"].split(""); // 分割储存信息为字符数组
    this.type = +storageInfo[1]; // 将第二个字符转为数字并赋值给type
    this.data = +storageInfo[0]; // 将第一个字符转为数字并赋值给data

    // 检查资源路径并设置ziyuanlujing
    if (t["资源路径"]) {
      this.ziyuanlujing = t["资源路径"]; // 使用提供的资源路径
    } else {
      this.ziyuanlujing = "zhutiIcon/" + this.type + "_" + this.data; // 默认资源路径
    }

    this.lockData = e; // 设置锁定数据
    this.updataView(); // 更新视图
  };
  /** 
 * @class _ctor
 * @description 该类用于处理视图更新逻辑。
 */
  _ctor.prototype.updataView = function () {
    const instance = this; // 使用const定义实例，替代var
    if (this.data !== null) {
      const currentData = this.data; // 使用更具可读性的常量替代原有变量
      const zhutiData = $zqcc_OverallSystem.sers().userSrv.getZhutiData();
      if (zhutiData.indexOf(+this.data + "_" + this.type) >= 0 || currentData === 0) {
        this.vicon.active = false;
        this.lockNode.active = true;
      } else {
        const acquisitionMethod = this.lockData["获取方式"];
        switch (acquisitionMethod) {
          case "晋级":
            instance.vicon.getChildByName("duanwei").active = true;
            instance.vicon.getChildByName("duanwei").children[0].getComponent(cc.Label).string = this.lockData["获取条件"];
            break;
          case "金币":
            instance.vicon.getChildByName("jinbi").active = true;
            instance.vicon.getChildByName("jinbi").children[0].getComponent(cc.Label).string = this.lockData["获取条件"];
            break;
          case "签到":
            instance.vicon.getChildByName("qiandao").active = true;
            break;
        }
      }

      if (this.type === 1) {
        this.lockNode.active = $zqcc_OverallSystem.sers().userSrv.getZhutiBg() !== this.data;
        this.xuanzhong.active = !this.lockNode.active;
      }

      if (this.type === 2) {
        const currentZhuti = $zqcc_OverallSystem.sers().userSrv.getZhuti();
        if (currentZhuti === this.data) {
          instance.vicon.active = false;
          instance.xuanzhong.active = true;
          instance.lockNode.active = false;
        } else {
          instance.xuanzhong.active = false;
          instance.lockNode.active = true;
        }
      }

      c.default.loadBundleRes("home", `image/${this.ziyuanlujing}`, function (loadedResource) {
        if (instance && instance.node) {
          instance.icon.spriteFrame = new cc.SpriteFrame(loadedResource);
        }
      });
    }
  };

  _ctor.prototype.onTouchStart = function () {
    const instance = this; // 使用const定义实例，替代var
    $zqcc_OverallSystem.mgrs().soundMgr.playBtnSound();
    const typeLabel = this.type === 1 ? "背景" : "牌色"; // 使用更具可读性的常量替代原有变量

    if (this.vicon.active) {
      const acquisitionMethod = this.lockData["获取方式"];
      const userData = $zqcc_OverallSystem.sers().userSrv.getUserData();
      const condition = this.lockData["获取条件"];
      const userZhutiData = $zqcc_OverallSystem.sers().userSrv.getZhutiData();

      switch (acquisitionMethod) {
        case "晋级":
          const levelIndex = this.jieduanName.indexOf(condition);
          if (userData.maxLevel < levelIndex + 1 && (window.tt || window.wx)) {
            $zqcc_OverallSystem.sers().uiSrv.showMessage(`达到${condition}段位，解锁该皮肤`);
            return;
          }
          userZhutiData.push(+this.data + "_" + this.type);
          $zqcc_OverallSystem.sers().userSrv.setZhutiData(userZhutiData);
          s.default.emit($GameEventType.EventType.DirectorEvent.pifugenghuan);
          break;

        case "金币":
          if (+$zqcc_OverallSystem.sers().userSrv.coin < +condition) {
            $zqcc_OverallSystem.sers().uiSrv.showMessage("金币不足");
            return;
          }
          $zqcc_OverallSystem.sers().userSrv.addCoin(-+condition);
          userZhutiData.push(+this.data + "_" + this.type);
          $zqcc_OverallSystem.sers().userSrv.setZhutiData(userZhutiData);
          s.default.emit($GameEventType.EventType.DirectorEvent.pifugenghuan);
          s.default.emit($GameEventType.EventType.UIEvent.SignInList);
          break;

        case "签到":
          $zqcc_OverallSystem.sers().uiSrv.showMessage("完成签到之后即可获得");
          break;

        default: // 处理其他情况（如观看视频解锁）
          $zqcc_OverallSystem.sers().platformSrv.platformApi.loadAndShowVideoAd(() => {
            userZhutiData.push(+instance.data + "_" + instance.type);
            $zqcc_OverallSystem.sers().userSrv.setZhutiData(userZhutiData);
            s.default.emit($GameEventType.EventType.DirectorEvent.pifugenghuan);
          }, () => { }, null, {
            scene: "皮肤解锁",
            event: `解锁${typeLabel}${this.data}`
          }, "common_video");
          break;
      }
    } else {
      cc.log(this.type);
      if (this.type === 1) {
        $zqcc_OverallSystem.sers().userSrv.setZhutiBg(this.data);
      } else {
        $zqcc_OverallSystem.sers().userSrv.setZhuti(this.data);
      }
      s.default.emit($GameEventType.EventType.DirectorEvent.pifugenghuan);
    }
  };

  cc__decorate([ccp_property(cc.Sprite)], _ctor.prototype, "icon", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "vicon", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "lockNode", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "xuanzhong", undefined);
  return cc__decorate([ccp_ccclass], _ctor);
}(l.default);
exports.default = def_zhutiListItem;